package com.nuoniu.sibanyun.controller.crm;


import com.nuoniu.sibanyun.common.BaseController;
import com.nuoniu.sibanyun.common.result.HttpResult;
import com.nuoniu.sibanyun.entity.crm.CrmRetailLevel;
import com.nuoniu.sibanyun.service.crm.ICrmRetailLevelService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 分销等级 前端控制器
 * </p>
 *
 * @author 小啊刚
 * @since 2022-05-24
 */
@RestController
@RequestMapping("/retail/level")
@Api(tags = "分销等级管理")
public class CrmRetailLevelController extends BaseController {

    @Autowired
    private ICrmRetailLevelService retailLevelService;

    @ApiOperation("获取列表")
    @GetMapping("getList")
    public HttpResult getList(CrmRetailLevel level) {
        return HttpResult.ok(retailLevelService.list());
    }

    @ApiOperation("保存")
    @PostMapping("save")
    public HttpResult save(@RequestBody CrmRetailLevel level) {
        retailLevelService.saveOrUpdate(level);
        return HttpResult.ok();
    }

    @ApiOperation("删除")
    @DeleteMapping("delete")
    public HttpResult delete(Long id) {
        if(id.equals(1)) {
            return HttpResult.error("默认等级,不能删除");
        }
        retailLevelService.removeById(id);
        return HttpResult.ok();
    }
}
